printwriter java append to file

115

printwriter java append to file -

public static void usingPrintWriter() throws IOException 
{
    String textToAppend = "Happy Learning !!";
     
    FileWriter fileWriter = new FileWriter("c:/temp/samplefile.txt", true); //Set true for append mode
    PrintWriter printWriter = new PrintWriter(fileWriter);
    printWriter.println(textToAppend);  //New line
    printWriter.close();
}

Comments

Submit
0 Comments